﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace ISchool
{
    class PanelList
    {
        //作者：向桂泽
        //描述：UI设计中对下拉菜单的设计

        private int panelIndex = 0;
        private int BeginX;
        private int BeginY;
        private int Iwidth;
        private int Iheight;
        private Panel<System.Windows.Forms.Panel> start;
        private Panel<System.Windows.Forms.Panel> temp;
        public PanelList(int beginX, int beginY, int iWIDTH, int iHEIGHT)
        {
            panelIndex = 0;
            BeginX = beginX;
            BeginY = beginY;
            Iwidth = iWIDTH;
            Iheight = iHEIGHT;
        }
        public void addPanel(Panel<System.Windows.Forms.Panel> dPanel)
        {
            if (panelIndex == 0)
            {
                start = dPanel;
                start.ID = 0;
                dPanel.IPanel.Location = new Point(BeginX, BeginY);
                panelIndex++;
                return;
            }
            else
            {
                temp = start;
                while (temp.Next != null)
                {
                    temp = temp.Next;
                }
                temp.Next = dPanel;
                temp.Next.ID = temp.ID + 1;
                temp = temp.Next;
                temp.IPanel.Location = new Point(BeginX, BeginY + panelIndex * Iheight);
                panelIndex++;

            }
        }
        public System.Windows.Forms.Panel getFirstPanel()
        {
            Panel<System.Windows.Forms.Panel> temp1;
            temp = start;
            if (start != null)
            {
                if (start.Next != null)
                {
                    start = start.Next;
                    return temp.IPanel;
                }
                else
                {
                    temp = start;
                    start = null;
                    return temp.IPanel;
                }
            }
            else
            {
                return null;
            }

        }
        public void ClearPanel()
        {
            Panel<System.Windows.Forms.Panel> temp1;
            if(panelIndex==0)return ;
            temp = start;
            while (temp.Next != null)
            {
                temp.IPanel.Controls.Clear();
                temp1= temp.Next;
                temp = null;
                temp = temp1;
            }
            panelIndex = 0;
        }

    }
    class Panel<T>
    {
        public T IPanel
        {
            get;
            set;
        }
        public Panel<T> Next
        {
            get;
            set;
        }
        public int LoctionX
        {
            get;
            set;
        }
        public int LoctionY
        {
            get;
            set;
        }
        public int ID
        {
            get;
            set;
        }
        public Panel(T d)
        {
            IPanel = d;
        }
    }
}
